#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
#define NUM 16
//char *const  _argv[NUM]={
//(char*)"ls",
//(char*)"-l",
//(char*)"-a",

int main(int argc,char* argv[],char* env[])
{
  //memset(_argv,"\0",NUM);
  
char *const  _argv[NUM]={
(char*)"mycmd",
(char*)"-a",
(char*)"-b",
NULL
};
char *const _env[NUM]={(char*)"my_val= 23333333333333333322",NULL};
  printf("父进程开始运行\n");
  pid_t pid=fork();
  if(pid==0)
  {
    printf("子进程正在执行\n");
    //execl("/usr/bin/ls","ls","-a","-l",NULL);
    //execlp("ls","ls","-a","-l",NULL);
    //execv("/usr/bin/ls",_argv);
//  execvpe("./mycmd",_argv,_env);
    //
  // execvpe("mycmd",_argv,_env);
    execle("./mycmd","mycmd","-a",NULL,env);
    
    exit(-1);
  }
  sleep(3);
  int status;
id_t res=waitpid(-1,&status,0);//阻塞式等待
  if(res>0)
    printf("等待子进程成功，exit code:%d\n",WEXITSTATUS(status));

  printf("父进程结束运行\n");
  return 0;
}
